<template>
  <div class="header">
      <router-link to='/' tag="div" class="header-back-icon" v-show='showAbs'>
          <div class="iconfont back-icon">&#xe624;</div>
      </router-link>
      <div class="header-info" :style="opacity" v-show="showFixed">
        <router-link to='/' tag="div" class="header-left">
          <div class="iconfont back-icon">&#xe624;</div>
        </router-link>
        <div class="header-title">详情页</div>
      </div>
  </div>
</template>
<script>
export default {
  name: 'detailHeader',
  data () {
    return {
      showAbs: true,
      showFixed: false,
      opacity: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      let scrollTop = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      if (scrollTop >= 50) {
        this.showAbs = false
        this.showFixed = true
      } else {
        this.showAbs = true
        this.showFixed = false
      }
      if (scrollTop >= 0 && scrollTop <= 60) {
        let scrollTopVal = scrollTop / 60
        this.opacity.opacity = scrollTopVal
        // console.log(scrollTop)
      } else if (scrollTop >= 80) {
        this.opacity.opacity = '1'
      }
    }

  },
  mounted () {
    // window.addEventListener('scroll', this.handleScroll)
    window.addEventListener('scroll', this.handleScroll)
  },
  beforeDestory () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  .header
    z-index 10
    .header-back-icon
      position absolute
      left: .2rem
      top 0.2rem
      z-index 10
      height 0.8rem
      width: .8rem
      border-radius: 50%
      background: rgba(0,0,0,.7)
      text-align: center
      line-height: .8rem
      .back-icon
        color: #fff
        font-size: .4rem
    .header-info
      position fixed
      top:0
      left: 0
      right: 0
      z-index 10
      display: flex
      font-size: .28rem
      line-height: .8rem
      background: #00bcd4
      .header-left
        height .8rem
        width 0.8rem
        line-height: .8rem
        text-align: center
        color: #fff
      .header-title
        flex: 1
        color: #fff
        line-height: .8rem
        text-align: center
        padding-right: .8rem
</style>
